package dnl.dtools.grm.operations.io;

import java.io.IOException;

import dnl.dtools.grm.LocalFileSystemEntry;
import dnl.dtools.grm.Resource;
import dnl.dtools.grm.operations.ResourceOperationException;
import dnl.dtools.grm.operations.TargetBasedResourceOperation;

/**
 * 
 * @author daniel
 */
public class LocalFsMoveOperation extends TargetBasedResourceOperation {

	public LocalFsMoveOperation(Resource[] sources, Resource target) {
		super(sources, target);
	}

	public int getProgress() {
		return 0;
	}

	@Override
	public void operate() throws ResourceOperationException {
		LocalFileSystemEntry r2 = (LocalFileSystemEntry) target;
		
		for (int i = 0; i < sources.length; i++) {
			LocalFileSystemEntry r1 = (LocalFileSystemEntry) sources[i];
			try {
				r1.renameTo(r2.getChild(r1.getName()));
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			double d = sources.length;
			d = i/d;
			setProgress(d);
		}
		
	}

}
